package com.kunbo.cn.controller.core.customer;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.entity.core.customer.CustomerManage;
import com.kunbo.cn.service.core.customer.CustomerManageService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

/**
 *客户用户Manage
 * @author  编写人:刘义
 * @date 时间:2019年3月18日下午1:13:26
 */
@RestController
@RequestMapping("/customer")
public class CustomerManageController {
	
	@Autowired
	private CustomerManageService service;
	
	/**
	 * 
	 * @param code
	 * @param customer
	 * @param loginName
	 * @param customerName
	 * @param password
	 * @param phone
	 * @param organization
	 * @param type
	 * @param effective
	 * @param explain
	 * @return
	 */
	@RequestMapping("/saveCustomer")
	public ResultBean<CustomerManage> saveCustomer(
			@RequestParam("customer_code")String code,
			@RequestParam("name")Integer customer,
			@RequestParam("login_name")String loginName, 
			@RequestParam("customer_name")String customerName, 
			@RequestParam("login_password")String password,
			@RequestParam("phone")String phone, 
			@RequestParam("affiliated_organization")String organization, 
			@RequestParam("type")String type, 
			@RequestParam("tives")Integer effective, 
			@RequestParam("explains")String explain
			
			){
		ResultBean<CustomerManage> result = new ResultBean<CustomerManage>();
		return BuildBean.buildResult(result, "success", "error", service.saveCustomer(code,customer,loginName,customerName,password,phone,organization,type,effective,explain));
	}
	
	
	
	/**
	 * 修改
	 * @param id
	 * @param code  编码
	 * @param loginName  登录名称
	 * @param customerName  用户名称
	 * @param affiliated_organization 所属组织
	 * @param effective 是否有效
	 * @param loginPassword 登录密码
	 * @param phone 手机号 
	 * @param explain 说明
	 * @param type 用户类型
	 * @return
	 */
	@RequestMapping("/updCustomer")
	public ResultBean<Boolean> updCustomer(
			@RequestParam("id")String id, 
			@RequestParam("customer_code")String code,
			@RequestParam("customer")Integer customer,
			@RequestParam("login_name")String loginName, 
			@RequestParam("customer_name")String customerName, 
			@RequestParam("login_password")String password,
			@RequestParam("phone")String phone, 
			@RequestParam("affiliated_organization")String organization, 
			@RequestParam("type")String type, 
			@RequestParam("tives")Integer effective, 
			@RequestParam("explains")String explain
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", service.updCustomer(id,code,customer,loginName,customerName,password,phone,organization,type,effective,explain));
	}
	
	
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@RequestMapping("/delCustomer")
	public ResultBean<Boolean> updCustomer(
			@RequestParam("id")String id //id
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", service.delCustomer(id));
	}
	
	
	/**
	 * 修改密码
	 * @param id
	 * @param password  新密码
	 * @return
	 */
	@RequestMapping("/updPasword")
	public ResultBean<Boolean> updPassword(
			@RequestParam("id")String id,
			@RequestParam("password")String password
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", service.updPassword(id,password));
	}
	
	
	/**
	 * 查询
	 * @param selConditionTypeId  查询条件id
	 * @param conditionValue 条件值
	 * @param organization 所属组织
	 * @param customer 客户
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/selCustomerList")
	public ResultBean<List<Map<String,Object>>> selCustomerList(
			@RequestParam("code")String code, 
			@RequestParam("customerName")String customerName, 
			@RequestParam("loginName")String loginName, 
			@RequestParam("page")Integer page, 
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "succes", service.selCustomerList(code,customerName,loginName,page,pageSize));
	}
	
	
	
	@PostMapping("/getById")
	public ResultBean<List<Map<String,Object>>> getById(
			@RequestParam("id")String id
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.getById(id));
	}
	
	
	
	

}
